using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWBFKOPF
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                default:
                case "TST":
                case "YGR":
                case "SXN":
                case "UBT":
                case "JLT":
                    #region
                    dwReturn["WBFKMANDANT"] = "00";
                    dwReturn["WBFKRWKRS"] = "  ";
                    dwReturn["WBFKRWLFD"] = "004026";
                    dwReturn["WBFKRWPOS"] = "0085";
                    dwReturn["WBFKVERSION"] = "1";
                    dwReturn["WBFKAENDZL"] = "1";
                    dwReturn["WBFKAENDBEN"] = "5       ";
                    dwReturn["WBFKAENDDAT"] = "20140714";
                    dwReturn["WBFKNEUBEN"] = "5       ";
                    dwReturn["WBFKNEUDAT"] = "20140714";
                    dwReturn["WBFKSART"] = " ";
                    dwReturn["WBFKSSEITE"] = "V";
                    dwReturn["WBFKSRICHT"] = "V";
                    dwReturn["WBFKSLAEKZ"] = "N";
                    dwReturn["WBFKWARSCH"] = "5       ";
                    dwReturn["WBFKWMNRKRS"] = "  ";
                    dwReturn["WBFKWMLFDNR"] = "0801";
                    dwReturn["WBFKWMPOS"] = "05";
                    dwReturn["WBFKLFPOS"] = "3";
                    dwReturn["WBFKISTKLG"] = "70320";
                    dwReturn["WBFKIGEW"] = "11040";
                    dwReturn["WBFKIBRT"] = "1460000";
                    dwReturn["WBFKENDEVERS"] = "J";
                    dwReturn["WBFKAUFKRS"] = "HZ";
                    dwReturn["WBFKAUFLFD"] = "000367";
                    dwReturn["WBFKAUFPOS"] = "001";
                    dwReturn["WBFKAFOLGE"] = "080";
                    dwReturn["WBFKAUFMPOS"] = "0000";
                    dwReturn["WBFKUSTKLG"] = "70320";
                    dwReturn["WBFKUGEW"] = "11040";
                    dwReturn["WBFKDIFFLG"] = "0";
                    dwReturn["WBFKDIFFGEW"] = "0";
                    dwReturn["WBFK1ALG"] = "70320";
                    dwReturn["WBFKURWAKZ"] = "F";
                    dwReturn["WBFKDFFSCHL"] = "   ";
                    dwReturn["WBFKDFKSTKRS"] = "  ";
                    dwReturn["WBFKDFKST"] = "0000";
                    dwReturn["WBFKDFKUNDNR"] = "        ";
                    dwReturn["WBFKDFLIEFNR"] = "        ";
                    dwReturn["WBFKFILLER"] = "0000                                    ";
                    #endregion
                    break;
            }
        }
        public void InsertWBFKOPF(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand(); 
            switch (app.company)
            {
                default:
                case "TST":
                case "YGR":
                case "SXN":
                case "UBT":
                case "JLT":
                    or1.CommandText = "INSERT INTO WBFKOPF ( WBFKMANDANT,WBFKRWKRS,WBFKRWLFD,WBFKRWPOS,WBFKVERSION,WBFKAENDZL,WBFKAENDBEN,WBFKAENDDAT,WBFKNEUBEN,WBFKNEUDAT,WBFKSART,WBFKSSEITE,WBFKSRICHT,WBFKSLAEKZ,WBFKWARSCH,WBFKWMNRKRS,WBFKWMLFDNR,WBFKWMPOS,WBFKLFPOS,WBFKISTKLG,WBFKIGEW,WBFKIBRT,WBFKENDEVERS,WBFKAUFKRS,WBFKAUFLFD,WBFKAUFPOS,WBFKAFOLGE,WBFKAUFMPOS,WBFKUSTKLG,WBFKUGEW,WBFKDIFFLG,WBFKDIFFGEW,WBFK1ALG,WBFKURWAKZ,WBFKDFFSCHL,WBFKDFKSTKRS,WBFKDFKST,WBFKDFKUNDNR,WBFKDFLIEFNR,WBFKFILLER)"
                   + " VALUES (:WBFKMANDANT:,:WBFKRWKRS:,:WBFKRWLFD:,:WBFKRWPOS:,:WBFKVERSION:,:WBFKAENDZL:,:WBFKAENDBEN:,:WBFKAENDDAT:,:WBFKNEUBEN:,:WBFKNEUDAT:,:WBFKSART:,:WBFKSSEITE:,:WBFKSRICHT:,:WBFKSLAEKZ:,:WBFKWARSCH:,:WBFKWMNRKRS:,:WBFKWMLFDNR:,:WBFKWMPOS:,:WBFKLFPOS:,:WBFKISTKLG:,:WBFKIGEW:,:WBFKIBRT:,:WBFKENDEVERS:,:WBFKAUFKRS:,:WBFKAUFLFD:,:WBFKAUFPOS:,:WBFKAFOLGE:,:WBFKAUFMPOS:,:WBFKUSTKLG:,:WBFKUGEW:,:WBFKDIFFLG:,:WBFKDIFFGEW:,:WBFK1ALG:,:WBFKURWAKZ:,:WBFKDFFSCHL:,:WBFKDFKSTKRS:,:WBFKDFKST:,:WBFKDFKUNDNR:,:WBFKDFLIEFNR:,:WBFKFILLER:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QWBFK01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();

            or1.CommandText = "SELECT * FROM WBFKOPF"
                + " WHERE WBFKMANDANT=:WBFKMANDANT: AND WBFKRWKRS=:WBFKRWKRS: AND WBFKRWLFD=:WBFKRWLFD: AND WBFKRWPOS=:WBFKRWPOS: AND WBFKVERSION=:WBFKVERSION:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QWBFK02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM WBFKOPF"
                + " WHERE WBFKMANDANT=:WBFKMANDANT: AND WBFKRWKRS=:WBFKRWKRS: AND WBFKRWLFD=:WBFKRWLFD: AND WBFKRWPOS=:WBFKRWPOS: "
                + " ORDER BY WBFKVERSION DESC";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QWBFK03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();

            or1.CommandText = "SELECT NVL(MAX(WBFKVERSION),'1') AS WBFKVERSION  FROM WBFKOPF"
                + " WHERE WBFKMANDANT=:WBFKMANDANT: AND WBFKRWKRS=:WBFKRWKRS: AND WBFKRWLFD=:WBFKRWLFD: AND WBFKRWPOS=:WBFKRWPOS:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QWBFKSTKNR(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand(); 
            or1.CommandText = "SELECT F.* FROM WBFKOPF F JOIN WBBST ON  WBFKMANDANT=WBBMANDANT AND WBFKRWKRS=WBBRWKRS AND WBFKRWLFD=WBBRWLFD AND WBFKRWPOS=WBBPOS "
                + " WHERE WBBMANDANT=:WBBMANDANT: AND WBBSTKNR=:WBBSTKNR:  "
                + " ORDER BY WBFKVERSION DESC";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public void DWBFK01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM WBFKOPF   "
             + " WHERE WBFKMANDANT=:WBFKMANDANT: AND WBFKRWKRS=:WBFKRWKRS: AND WBFKRWLFD=:WBFKRWLFD: AND WBFKRWPOS=:WBFKRWPOS: AND WBFKVERSION=:WBFKVERSION:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void DWBFK02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM WBFKOPF   "
             + " WHERE WBFKMANDANT=:WBFKMANDANT: AND WBFKRWKRS=:WBFKRWKRS: AND WBFKRWLFD=:WBFKRWLFD: AND WBFKRWPOS=:WBFKRWPOS:  ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }


        public void UpdateWBFKOPF(DataRow dwData, int option = 1)
        {
            dwData["WBFKAENDBEN"] = app.User;
            dwMaster["WBFKAENDDAT"] = date;
            if (option == 0)
            {
                switch (app.company)
                {
                    default:
                    case "TST":
                    case "YGR":
                    case "SXN":
                    case "UBT":
                    case "JLT":
                        UWBFK01(dwData);
                        break;
                }
            }

        }
        public void UWBFK01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE WBFKOPF SET WBFKMANDANT=:WBFKMANDANT:,WBFKRWKRS=:WBFKRWKRS:,WBFKRWLFD=:WBFKRWLFD:,WBFKRWPOS=:WBFKRWPOS:,WBFKVERSION=:WBFKVERSION:,WBFKAENDZL=:WBFKAENDZL:,WBFKAENDBEN=:WBFKAENDBEN:,WBFKAENDDAT=:WBFKAENDDAT:,WBFKNEUBEN=:WBFKNEUBEN:,WBFKNEUDAT=:WBFKNEUDAT:,WBFKSART=:WBFKSART:,WBFKSSEITE=:WBFKSSEITE:,WBFKSRICHT=:WBFKSRICHT:,WBFKSLAEKZ=:WBFKSLAEKZ:,WBFKWARSCH=:WBFKWARSCH:,WBFKWMNRKRS=:WBFKWMNRKRS:,WBFKWMLFDNR=:WBFKWMLFDNR:,WBFKWMPOS=:WBFKWMPOS:,WBFKLFPOS=:WBFKLFPOS:,WBFKISTKLG=:WBFKISTKLG:,WBFKIGEW=:WBFKIGEW:,WBFKIBRT=:WBFKIBRT:,WBFKENDEVERS=:WBFKENDEVERS:,WBFKAUFKRS=:WBFKAUFKRS:,WBFKAUFLFD=:WBFKAUFLFD:,WBFKAUFPOS=:WBFKAUFPOS:,WBFKAFOLGE=:WBFKAFOLGE:,WBFKAUFMPOS=:WBFKAUFMPOS:,WBFKUSTKLG=:WBFKUSTKLG:,WBFKUGEW=:WBFKUGEW:,WBFKDIFFLG=:WBFKDIFFLG:,WBFKDIFFGEW=:WBFKDIFFGEW:,WBFK1ALG=:WBFK1ALG:,WBFKURWAKZ=:WBFKURWAKZ:,WBFKDFFSCHL=:WBFKDFFSCHL:,WBFKDFKSTKRS=:WBFKDFKSTKRS:,WBFKDFKST=:WBFKDFKST:,WBFKDFKUNDNR=:WBFKDFKUNDNR:,WBFKDFLIEFNR=:WBFKDFLIEFNR:,WBFKFILLER=:WBFKFILLER:"
                + " WHERE WBFKMANDANT=:WBFKMANDANT: AND WBFKRWKRS=:WBFKRWKRS: AND WBFKRWLFD=:WBFKRWLFD: AND WBFKRWPOS=:WBFKRWPOS: AND WBFKVERSION=:WBFKVERSION:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
    }
}
